import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:top_foundation/utils/theme/theme.dart';
import 'package:whale/helper/utils/screen_shot.dart';
import 'package:whale/helper/utils/util.dart';

import '../../../home/main/widgets/hello.dart';
import 'index.dart';
import 'widgets/widgets.dart';

class ScreenShotDemoPage extends GetView<ScreenShotDemoController> {
  const ScreenShotDemoPage({Key? key}) : super(key: key);

  Widget _cell(
    String title,
    bool isOn, {
    required ValueChanged<bool> onChanged,
  }) {
    return TitleContentItemView(
      title: title,
      contentWidget: CupertinoSwitch(
        value: isOn,
        onChanged: onChanged,
      ),
      border: Border(bottom: ITheme.borderSide),
      padding: EdgeInsets.symmetric(horizontal: 12.r),
      hasArrow: false,
    );
  }

  // 主视图
  Widget _buildView() {
    final man = ScreenShotMan();

    return ListView(children: [
      // Textcell(
      //   text: '截屏替换成其他图片',
      //   onTap: () {
      //     man.protectWithImage();
      //   },
      // ),
      // _cell('截屏替换成白色图片', man.isDisableWithColor, onChanged: (p0) async {
      //   Get.log('ddddd--------');
      //   if (p0) {
      //     await man.protectWithColorOn();
      //   } else {
      //     await man.protectWithColorOff();
      //   }
      //   controller.update();
      // }),
      _cell('禁止截屏录屏', man.isDisable, onChanged: (p0) async {
        if (p0) {
          await man.disable();
        } else {
          await man.enable();
        }
        controller.update();
      })
    ]);
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ScreenShotDemoController>(
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: const Text("限制屏幕截图录像样例")),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
